<template>
    <div>
        <!-- 
            在vue中三种方式可以阻止事件冒泡
            1、event.stopPropogation()
            2、stop修饰符：子元素中使用
            3、self修饰符:在父元素中使用
         -->
        <h1>事件冒泡</h1>
        <div class="parent" @click.self="clickParent">
            <div class="child" @click="clickChild"></div>
        </div>
        <hr>
        <h1>阻止默认行为</h1>
        <a href="http://www.woniuxy.com" @click.prevent="clickMe">🐌</a>
        <hr>
        <h1>事件捕获</h1>
         <div class="parent" @click.capture="clickParent">
            <div class="child" @click="clickChild"></div>
        </div>
        <hr>
        <h1>只单击一次</h1>
        <button @click.once="clickYou">点击我</button>
    </div>
</template>

<script>
export default {
    methods:{
        clickParent(){
            console.log('parent......');
        },
        clickChild(e){
            console.log('child........');
            //e.stopPropagation()//阻止了事件冒泡
        },
        clickMe(e){
            //e.preventDefault()
            console.log('=======我被点击了=========');
            alert('蜗牛学院欢迎您')
            window.location.href="http://www.zhaijizhe.cn"   
        },
        clickYou(){
            alert('蜗牛学院欢迎您')
        }
    }
}
</script>

<style lang="scss">
    .parent{
        width: 100px;
        height: 100px;
        background-color: red;
        border-radius: 50%;
    }
    .child{
        width: 60px;
        height: 60px;
        background-color: orange;
        border-radius: 50%;
    }
</style>